<?php
	class ComentarioNoticia extends Utilitarios{

		private $id;
		private $obj_noticia;		
		private $fecha;
		private $nombre;
		private $email;
		private $comentario;

		public function __construct($id = 0){
			$this->id = $id;
			if($this->id > 0){
				$sql = "SELECT * FROM noticias_comentarios WHERE id_noticia_comentario = ".$id;
				$query = new Consulta($sql);
				if($query->NumeroRegistros() > 0){
					$row = $query->VerRegistro();
					$this->obj_noticia 		= new Noticia($row['id_noticia']);
					$this->fecha 			= $row['fecha'];
					$this->nombre		 	= $row['nombre'];
					$this->email			= $row['email'];
					$this->comentario 		= $row['comentario'];
				}					
			}
		}

		public function __get($atributo){
			return $this->$atributo;
		}

		public function getComentariosPorNoticia($id){
			$sql = "SELECT * FROM noticias_comentarios WHERE id_noticia = ".$id." ORDER BY fecha ASC";
			$query = new Consulta($sql);
			while( $row = $query->VerRegistro() ){
				$result[] = array(
					'id'			=> $row['id_noticia_comentario'],
					'id_noticia'	=> $row['id_noticia'],
					'fecha'			=> $row['fecha'],
					'nombre' 		=> $row['nombre'],
					'email' 		=> $row['email'],
					'comentario'	=> $row['comentario']
				);
			}
			return $result;
		}

		public function getComentarioJson($id){
			$sql = "SELECT * FROM noticias_comentarios WHERE id_noticia_comentario = ".$id;
			$query = new Consulta($sql);
			while( $row = $query->VerRegistro() ){
				$result[] = array(
					'id'			=> $row['id_noticia_comentario'],
					'id_noticia'	=> $row['id_noticia'],
					'fecha'			=> $this->fecha_salida( substr($row['fecha'],0,10) )." ".substr($row['fecha'],11,8),
					'nombre' 		=> $row['nombre'],
					'email' 		=> $row['email'],
					'comentario'	=> $row['comentario']
				);
			}
			return $result;
		}
		
	}
?>